/*
 * _Bai02_PhanTichPhanKhaiBaoView.java
 */

package _bai02_phantichphankhaibao;

import java.awt.Color;
import java.io.FileNotFoundException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;

/**
 * The application's main frame.
 */
public class _Bai02_PhanTichPhanKhaiBaoView extends FrameView {

    private jClass_CacStyleChuoi cacStyleChuoi = new jClass_CacStyleChuoi();
    public _Bai02_PhanTichPhanKhaiBaoView(SingleFrameApplication app) {
        super(app);

        initComponents();
        toMau_HighlightSyntax();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = _Bai02_PhanTichPhanKhaiBaoApp.getApplication().getMainFrame();
            aboutBox = new _Bai02_PhanTichPhanKhaiBaoAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        _Bai02_PhanTichPhanKhaiBaoApp.getApplication().show(aboutBox);
    }

    private boolean caretCapNhat() throws NumberFormatException {
        // TODO add your handling code here:
        jClass_PhanKhaiBao jPKB_PhanKhaiBao = new jClass_PhanKhaiBao();
        //Boolean b_HopDinhDang = jPKB_PhanKhaiBao.jKiemTraChuoiHopDinhDang(jTextPane_PhanNhapKhaiBao.getText());
        jClass_Loi jCL_Loi = jPKB_PhanKhaiBao.jKiemTraLoiCuaBieuThucDuocNhap(jTextPane_PhanNhapKhaiBao.getText().trim().split("\n")[0]);
        if (jCL_Loi.getMoTa() == jEnum_Loi.KhongCoLoi) {
            //jPKB_PhanKhaiBao.jCapNhatTuChuoi(jTextPane_PhanNhapKhaiBao.getText());
            //jButton_PhanTich.setEnabled(true);
            jLabel_ThongBaoLoi.setVisible(false);
        } else {
            //Nếu có lỗi
            //jButton_PhanTich.setEnabled(false);
            jLabel_ThongBaoLoi.setVisible(true);
            jLabel_ThongBaoLoi.setText(jCL_Loi.getMoTa().value());
            if (jCL_Loi.getMoTa() == jEnum_Loi.ChuoiKhaiBaoSaiDinhDang) {
                return true;
            }
            jClass_Bien jB_BienCoLoi = jPKB_PhanKhaiBao.getGiaTriTraVe();
            //Lấy stt biến có lỗi từ thông tin bổ sung của lỗi
            int i_STTBienCoLoi = Integer.valueOf(jCL_Loi.getThongTinBoSung());
            if (i_STTBienCoLoi != -1) {
                //Biến bị trùng tên không phải giá trị trả về
                jB_BienCoLoi = jPKB_PhanKhaiBao.getCacThamSo().get(i_STTBienCoLoi);
            }
            if (jCL_Loi.getMoTa() == jEnum_Loi.CacBienTrungTen) {
                //Tô màu tên biến có lỗi
                toMau_LoiTrungTenBien(jB_BienCoLoi.getTen());
            }
            if (jCL_Loi.getMoTa() == jEnum_Loi.KieuDuLieuKhongDuocHoTro) {
                //Tô màu kiểu dữ liệu có lỗi
                toMau_LoiKieuDuLieu(jB_BienCoLoi);
            }
        }
        return false;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextPane_PhanNhapKhaiBao = new javax.swing.JTextPane();
        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextPane_PhanKetQuaPhanTich = new javax.swing.JTextPane();
        jPanel3 = new javax.swing.JPanel();
        jButton_PhanTich = new javax.swing.JButton();
        jButton_MoFile = new javax.swing.JButton();
        jButton_Luu = new javax.swing.JButton();
        jComboBox_ViDuMau = new javax.swing.JComboBox();
        jButton_PhanTich1 = new javax.swing.JButton();
        jLabel_ThongBaoLoi = new javax.swing.JLabel();
        jButton_Thoat = new javax.swing.JButton();
        jPanel_Code = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTextPane_PhanCodeDuocTao = new javax.swing.JTextPane();
        jCheckBox_TaoHamMain = new javax.swing.JCheckBox();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();

        mainPanel.setName("mainPanel"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(_bai02_phantichphankhaibao._Bai02_PhanTichPhanKhaiBaoApp.class).getContext().getResourceMap(_Bai02_PhanTichPhanKhaiBaoView.class);
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel1.border.title"))); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N

        jScrollPane5.setBorder(null);
        jScrollPane5.setAutoscrolls(true);
        jScrollPane5.setName("jScrollPane5"); // NOI18N
        jScrollPane5.setPreferredSize(new java.awt.Dimension(500, 50));

        jScrollPane1.setAutoscrolls(true);
        jScrollPane1.setName("jScrollPane1"); // NOI18N
        jScrollPane1.setPreferredSize(new java.awt.Dimension(500, 22));

        jTextPane_PhanNhapKhaiBao.setText(resourceMap.getString("jTextPane_PhanNhapKhaiBao.text")); // NOI18N
        jTextPane_PhanNhapKhaiBao.setName("jTextPane_PhanNhapKhaiBao"); // NOI18N
        jTextPane_PhanNhapKhaiBao.setPreferredSize(new java.awt.Dimension(500, 20));
        jTextPane_PhanNhapKhaiBao.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                jTextPane_PhanNhapKhaiBaoCaretUpdate(evt);
            }
        });
        jTextPane_PhanNhapKhaiBao.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jTextPane_PhanNhapKhaiBaoPropertyChange(evt);
            }
        });
        jTextPane_PhanNhapKhaiBao.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextPane_PhanNhapKhaiBaoKeyReleased(evt);
            }
        });
        jScrollPane1.setViewportView(jTextPane_PhanNhapKhaiBao);

        jScrollPane5.setViewportView(jScrollPane1);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 338, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(53, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 243, Short.MAX_VALUE)
        );

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel2.border.title"))); // NOI18N
        jPanel2.setName("jPanel2"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jTextPane_PhanKetQuaPhanTich.setEditable(false);
        jTextPane_PhanKetQuaPhanTich.setName("jTextPane_PhanKetQuaPhanTich"); // NOI18N
        jScrollPane2.setViewportView(jTextPane_PhanKetQuaPhanTich);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 370, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE)
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel3.border.title"))); // NOI18N
        jPanel3.setName("jPanel3"); // NOI18N

        jButton_PhanTich.setText(resourceMap.getString("jButton_PhanTich.text")); // NOI18N
        jButton_PhanTich.setName("jButton_PhanTich"); // NOI18N
        jButton_PhanTich.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_PhanTichActionPerformed(evt);
            }
        });

        jButton_MoFile.setText(resourceMap.getString("jButton_MoFile.text")); // NOI18N
        jButton_MoFile.setName("jButton_MoFile"); // NOI18N
        jButton_MoFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_MoFileActionPerformed(evt);
            }
        });

        jButton_Luu.setText(resourceMap.getString("jButton_Luu.text")); // NOI18N
        jButton_Luu.setName("jButton_Luu"); // NOI18N
        jButton_Luu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_LuuActionPerformed(evt);
            }
        });

        jComboBox_ViDuMau.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Bài 1", "Bài 2", " " }));
        jComboBox_ViDuMau.setName("jComboBox_ViDuMau"); // NOI18N
        jComboBox_ViDuMau.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox_ViDuMauActionPerformed(evt);
            }
        });

        jButton_PhanTich1.setText(resourceMap.getString("jButton_PhanTich1.text")); // NOI18N
        jButton_PhanTich1.setName("jButton_PhanTich1"); // NOI18N
        jButton_PhanTich1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_PhanTich1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jButton_MoFile)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton_Luu)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBox_ViDuMau, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(149, 149, 149)
                        .addComponent(jButton_PhanTich1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton_PhanTich)))
                .addContainerGap(21, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_MoFile, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton_Luu, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jComboBox_ViDuMau, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(58, 58, 58)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_PhanTich1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton_PhanTich, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );

        jLabel_ThongBaoLoi.setForeground(resourceMap.getColor("jLabel_ThongBaoLoi.foreground")); // NOI18N
        jLabel_ThongBaoLoi.setText(resourceMap.getString("jLabel_ThongBaoLoi.text")); // NOI18N
        jLabel_ThongBaoLoi.setName("jLabel_ThongBaoLoi"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(_bai02_phantichphankhaibao._Bai02_PhanTichPhanKhaiBaoApp.class).getContext().getActionMap(_Bai02_PhanTichPhanKhaiBaoView.class, this);
        jButton_Thoat.setAction(actionMap.get("quit")); // NOI18N
        jButton_Thoat.setText(resourceMap.getString("jButton_Thoat.text")); // NOI18N
        jButton_Thoat.setName("jButton_Thoat"); // NOI18N

        jPanel_Code.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel_Code.border.title"))); // NOI18N
        jPanel_Code.setAutoscrolls(true);
        jPanel_Code.setName("jPanel_Code"); // NOI18N
        jPanel_Code.setPreferredSize(new java.awt.Dimension(4, 5));

        jScrollPane4.setName("jScrollPane4"); // NOI18N

        jScrollPane3.setName("jScrollPane3"); // NOI18N
        jScrollPane3.setPreferredSize(new java.awt.Dimension(5000, 10000));

        jTextPane_PhanCodeDuocTao.setEditable(false);
        jTextPane_PhanCodeDuocTao.setMinimumSize(new java.awt.Dimension(2000, 2000));
        jTextPane_PhanCodeDuocTao.setName("jTextPane_PhanCodeDuocTao"); // NOI18N
        jTextPane_PhanCodeDuocTao.setPreferredSize(new java.awt.Dimension(2000, 2000));
        jScrollPane3.setViewportView(jTextPane_PhanCodeDuocTao);

        jScrollPane4.setViewportView(jScrollPane3);

        javax.swing.GroupLayout jPanel_CodeLayout = new javax.swing.GroupLayout(jPanel_Code);
        jPanel_Code.setLayout(jPanel_CodeLayout);
        jPanel_CodeLayout.setHorizontalGroup(
            jPanel_CodeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 431, Short.MAX_VALUE)
        );
        jPanel_CodeLayout.setVerticalGroup(
            jPanel_CodeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 504, Short.MAX_VALUE)
        );

        jCheckBox_TaoHamMain.setSelected(true);
        jCheckBox_TaoHamMain.setText(resourceMap.getString("jCheckBox_TaoHamMain.text")); // NOI18N
        jCheckBox_TaoHamMain.setToolTipText(resourceMap.getString("jCheckBox_TaoHamMain.toolTipText")); // NOI18N
        jCheckBox_TaoHamMain.setName("jCheckBox_TaoHamMain"); // NOI18N

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 866, Short.MAX_VALUE)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(jLabel_ThongBaoLoi)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addComponent(jCheckBox_TaoHamMain, javax.swing.GroupLayout.DEFAULT_SIZE, 352, Short.MAX_VALUE)
                                .addGap(15, 15, 15)
                                .addComponent(jButton_Thoat, javax.swing.GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE))
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addGap(6, 6, 6)
                                .addComponent(jPanel_Code, javax.swing.GroupLayout.DEFAULT_SIZE, 447, Short.MAX_VALUE)))))
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addGap(11, 11, 11)
                                .addComponent(jLabel_ThongBaoLoi, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addGap(25, 25, 25)
                                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                        .addComponent(jPanel_Code, javax.swing.GroupLayout.DEFAULT_SIZE, 534, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jCheckBox_TaoHamMain, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton_Thoat, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addGap(18, 18, 18))
        );

        jLabel_ThongBaoLoi.getAccessibleContext().setAccessibleName(resourceMap.getString("jLabel2.AccessibleContext.accessibleName")); // NOI18N

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 886, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 716, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton_PhanTichActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_PhanTichActionPerformed
        //Lay Chuoi duoc nhap
        String Str_KhaiBao = jTextPane_PhanNhapKhaiBao.getText();
/*        jClass_PhanKhaiBao jPKB_KhaiBao = new jClass_PhanKhaiBao();

        if (jPKB_KhaiBao.jKiemTraLoiCuaBieuThucDuocNhap(Str_KhaiBao).getMoTa() != jEnum_Loi.KhongCoLoi){
            JOptionPane.showMessageDialog(null, "Có lỗi trong phần dữ liệu đầu vào. Xin kiểm tra lại!");
            return;
        }

        //Lay Chuoi Ket Qua de xuat ra man hinh
        String Str_KetQua = jPKB_KhaiBao.toString();
        jTextPane_PhanKetQuaPhanTich.setText(Str_KetQua);

        jClass_PhanDacTa jPDT_DacTa = new jClass_PhanDacTa();
        jPDT_DacTa.setPhanKhaiBao(jPKB_KhaiBao);
        String str_Code = jClass_BoTaoCode.jTaoCode(jPDT_DacTa);
//        if (jCheckBox_TaoHamMain.isSelected())
*/
        String str_Code = phatSinhCode(Str_KhaiBao);
        jTextPane_PhanCodeDuocTao.setText(str_Code);
    }//GEN-LAST:event_jButton_PhanTichActionPerformed
    private String phatSinhCode (String dacTa){
        String Kq = "";
        jClass_PhanDacTa phanDacTa = new jClass_PhanDacTa();
        phanDacTa.jCapNhatTuChuoi(dacTa);
        Kq = phanDacTa.jToCCode(0);
        return Kq;
    }

    private String phatSinhCodeCS(String dacTa){
        String Kq = "";
        jClass_PhanDacTa phanDacTa = new jClass_PhanDacTa();
        phanDacTa.jCapNhatTuChuoi(dacTa);
        Kq = phanDacTa.jCSharpCode(0);
        return Kq;
    }
    private File moDialogChonFile()
    {
        File Kq = null;
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        fileChooser.setCurrentDirectory(new File(".").getAbsoluteFile().getParentFile());
        int ketQuaShowOpenDialog = fileChooser.showOpenDialog(null);
        if (ketQuaShowOpenDialog == JFileChooser.APPROVE_OPTION){
            Kq = fileChooser.getSelectedFile();
        }
        return Kq;
    }
    static public String getContents(File aFile) {
        //...checks on aFile are elided
        StringBuilder contents = new StringBuilder();

        try {
          //use buffering, reading one line at a time
          //FileReader always assumes default encoding is OK!
          BufferedReader input =  new BufferedReader(new FileReader(aFile));
          try {
            String line = null; //not declared within while loop
            /*
            * readLine is a bit quirky :
            * it returns the content of a line MINUS the newline.
            * it returns null only for the END of the stream.
            * it returns an empty String if two newlines appear in a row.
            */
            while (( line = input.readLine()) != null){
              contents.append(line);
              contents.append(System.getProperty("line.separator"));
            }
          }
          finally {
            input.close();
          }
        }
        catch (IOException ex){
          ex.printStackTrace();
        }

        return contents.toString();
    }
    private void jButton_MoFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_MoFileActionPerformed
        // TODO add your handling code here:
        File file = moDialogChonFile();
        if (file != null){
            String content = getContents(file);
            jTextPane_PhanNhapKhaiBao.setText(content);
            toMau_HighlightSyntax();
            caretCapNhat();
        }
}//GEN-LAST:event_jButton_MoFileActionPerformed

    private void jTextPane_PhanNhapKhaiBaoPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jTextPane_PhanNhapKhaiBaoPropertyChange
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextPane_PhanNhapKhaiBaoPropertyChange

    private void jTextPane_PhanNhapKhaiBaoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextPane_PhanNhapKhaiBaoKeyReleased
        // TODO add your handling code here:
        
        toMau_TraTatCaVeDangChuThuong();
        toMau_HighlightSyntax();
        jTextPane_PhanNhapKhaiBaoCaretUpdate(null);
    }//GEN-LAST:event_jTextPane_PhanNhapKhaiBaoKeyReleased

    private void jTextPane_PhanNhapKhaiBaoCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_jTextPane_PhanNhapKhaiBaoCaretUpdate
        //jPKB_PhanKhaiBao.jCapNhatTuChuoi(jTextPane_PhanNhapKhaiBao.getText());
        if (caretCapNhat())return;
    }//GEN-LAST:event_jTextPane_PhanNhapKhaiBaoCaretUpdate
    static public void setContents(File aFile, String string) {
        //...checks on aFile are elided
        StringBuilder contents = new StringBuilder();

        try {
          //use buffering, reading one line at a time
          //FileReader always assumes default encoding is OK!
          BufferedWriter output =  new BufferedWriter(new FileWriter(aFile));
          try {
            output.write(string, 0, string.length());
          }
          finally {
            output.close();
          }
        }
        catch (IOException ex){
          ex.printStackTrace();
        }
    }
    private void jButton_LuuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_LuuActionPerformed
        // TODO add your handling code here:
        File Kq = null;
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        fileChooser.setCurrentDirectory(new File(".").getAbsoluteFile().getParentFile());
        int ketQuaShowOpenDialog = fileChooser.showSaveDialog(null);
        if (ketQuaShowOpenDialog == JFileChooser.APPROVE_OPTION){
            Kq = fileChooser.getSelectedFile();
            setContents(Kq, jTextPane_PhanCodeDuocTao.getText());
        }

}//GEN-LAST:event_jButton_LuuActionPerformed

    private void jComboBox_ViDuMauActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox_ViDuMauActionPerformed
        // TODO add your handling code here:
        if (jComboBox_ViDuMau.getSelectedItem().toString().equalsIgnoreCase("bài 1")){
            jTextPane_PhanNhapKhaiBao.setText("KiemTraNamNhuan (n: N) Kq:B\npre \tn > 0\npost \t((Kq = true) /\\ (n % 4 = 0) /\\ (n % 100 <> 0) )\\/ ((Kq = true) /\\ (n % 400 = 0)) \\/((Kq = false) /\\ (n % 100 = 0) /\\ (n%400 <>0))\\/((Kq = false) /\\ (n % 100 <> 0) /\\ (n%4 <> 0))\n");
            toMau_HighlightSyntax();
            caretCapNhat();
        }
        if (jComboBox_ViDuMau.getSelectedItem().toString().equalsIgnoreCase("bài 2")){
                jTextPane_PhanNhapKhaiBao.setText("KTMangGiaTriChan (a:N*, n:N)kq:B\npre\npost kq = (VM i TH {0..n-1}. a[i] % 2 = 0)");
            toMau_HighlightSyntax();
            caretCapNhat();
        }
    }//GEN-LAST:event_jComboBox_ViDuMauActionPerformed

    private void jButton_PhanTich1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_PhanTich1ActionPerformed
        // TODO add your handling code here:
        String Str_KhaiBao = jTextPane_PhanNhapKhaiBao.getText();
/*        jClass_PhanKhaiBao jPKB_KhaiBao = new jClass_PhanKhaiBao();

        if (jPKB_KhaiBao.jKiemTraLoiCuaBieuThucDuocNhap(Str_KhaiBao).getMoTa() != jEnum_Loi.KhongCoLoi){
            JOptionPane.showMessageDialog(null, "Có lỗi trong phần dữ liệu đầu vào. Xin kiểm tra lại!");
            return;
        }

        //Lay Chuoi Ket Qua de xuat ra man hinh
        String Str_KetQua = jPKB_KhaiBao.toString();
        jTextPane_PhanKetQuaPhanTich.setText(Str_KetQua);

        jClass_PhanDacTa jPDT_DacTa = new jClass_PhanDacTa();
        jPDT_DacTa.setPhanKhaiBao(jPKB_KhaiBao);
        String str_Code = jClass_BoTaoCode.jTaoCode(jPDT_DacTa);
//        if (jCheckBox_TaoHamMain.isSelected())
*/
        String str_Code = phatSinhCodeCS(Str_KhaiBao);
        jTextPane_PhanCodeDuocTao.setText(str_Code);
    }//GEN-LAST:event_jButton_PhanTich1ActionPerformed
    /**
     * Tô màu biến có lỗi
     * @param jCB_Bien Tên biến cần tô màu
     */
    private void toMau_LoiTrungTenBien (String str_TenBien){
        String str_ChuoiKhaiBao = jTextPane_PhanNhapKhaiBao.getText();
        //Tìm vị trí cuối cùng có dạng " jCB_Bien"
        int i_STTTruongHopCoKhoangTrang = str_ChuoiKhaiBao.lastIndexOf(str_TenBien + " ");
        //Tìm vị trí cuối cùng có dạng ":jCB_Bien"
        int i_STTTruongHopKhongCoKhoangTrang = str_ChuoiKhaiBao.lastIndexOf(str_TenBien + ":");

        //Vị trí nào đứng sau sẽ là vị trí cần tô màu
        int i_STTViTriCanTo = 0;
        if (i_STTTruongHopCoKhoangTrang > i_STTTruongHopKhongCoKhoangTrang)
            i_STTViTriCanTo = i_STTTruongHopCoKhoangTrang;
        else
            i_STTViTriCanTo = i_STTTruongHopKhongCoKhoangTrang;

        //Tạo AttributeSet chữ in nghiêng màu đỏ.
        MutableAttributeSet mA_Loi = new SimpleAttributeSet();
        StyleConstants.setForeground(mA_Loi, Color.RED);
        StyleConstants.setItalic(mA_Loi, true);

        StyledDocument doc = jTextPane_PhanNhapKhaiBao.getStyledDocument();
        doc.setCharacterAttributes(i_STTViTriCanTo, str_TenBien.length(), mA_Loi, false);
        jTextPane_PhanNhapKhaiBao.setDocument(doc);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton_Luu;
    private javax.swing.JButton jButton_MoFile;
    private javax.swing.JButton jButton_PhanTich;
    private javax.swing.JButton jButton_PhanTich1;
    private javax.swing.JButton jButton_Thoat;
    private javax.swing.JCheckBox jCheckBox_TaoHamMain;
    private javax.swing.JComboBox jComboBox_ViDuMau;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel_ThongBaoLoi;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel_Code;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JTextPane jTextPane_PhanCodeDuocTao;
    private javax.swing.JTextPane jTextPane_PhanKetQuaPhanTich;
    private javax.swing.JTextPane jTextPane_PhanNhapKhaiBao;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    // End of variables declaration//GEN-END:variables

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;

    private JDialog aboutBox;
    private void toMau_TraTatCaVeDangChuThuong() {
        //Nếu không có lổi thì tô màu lại, bật (true) button  Phân tích và ẩn (false) thông báo lỗi
        //Tạo AttributeSet chữ bình thường
        /*MutableAttributeSet mA_Loi = new SimpleAttributeSet();
        StyleConstants.setForeground(mA_Loi, Color.BLACK);
        StyleConstants.setItalic(mA_Loi, false);
        StyleConstants.setBold(mA_Loi, false);*/
        MutableAttributeSet mA_ChuThuong = cacStyleChuoi.mChuThuong;
        StyledDocument doc = jTextPane_PhanNhapKhaiBao.getStyledDocument();
        doc.setCharacterAttributes(0, jTextPane_PhanNhapKhaiBao.getText().length(), mA_ChuThuong, false);
    }
    private void toMau_HighlightSyntax(){
        String str_KhaiBao = jTextPane_PhanNhapKhaiBao.getText();

    /*--------------------------------------------------------------------------------------------
     Tạo các AttributeSet*/
        /*//Tạo AttributeSet chữ bình thường
        MutableAttributeSet mA_ChuThuong = new SimpleAttributeSet();
        StyleConstants.setForeground(mA_ChuThuong, Color.BLACK);
        StyleConstants.setItalic(mA_ChuThuong, false);
        StyleConstants.setBold(mA_ChuThuong, false);

        //Tạo AttributeSet tên hàm
        MutableAttributeSet mA_TenHam = new SimpleAttributeSet();
        StyleConstants.setForeground(mA_TenHam, Color.BLACK);
        StyleConstants.setBold(mA_TenHam, true);

        //Tạo AttributeSet tên biến
        MutableAttributeSet mA_TenBien = new SimpleAttributeSet();
        StyleConstants.setForeground(mA_TenBien, Color.MAGENTA);

        //Tạo AttributeSet kiểu dữ liệu
        MutableAttributeSet mA_KieuDuLieu = new SimpleAttributeSet();
        StyleConstants.setForeground(mA_KieuDuLieu, Color.BLUE);*/
        //MutableAttributeSet mA_ChuThuong = new SimpleAttributeSet();
        MutableAttributeSet mA_TenHam = cacStyleChuoi.mTenHam;
        MutableAttributeSet mA_TenBien = cacStyleChuoi.mTenBien;
        MutableAttributeSet mA_KieuDuLieu = cacStyleChuoi.mKieuDuLieu;

        StyledDocument sD_Doc = jTextPane_PhanNhapKhaiBao.getStyledDocument();
    /*--------------------------------------------------------------------------------------------*/
    //Tô màu phần tên hàm
        int i_STTViTriDau = 0;
        int i_DoDaiCanTo = 0;
        //Tách tên hàm ra khỏi các phần còn lại
        String Str_KyTuTachChuoi = jEnum_DauPhanCach.TenHam_PhanConLai.value();//jEnum_DauPhanCach.TenHam_PhanConLai.value();
        //kiểm tra xem người dùng đã đánh xong tên hàm chưa dựa vào dấu "("
        if (!str_KhaiBao.contains(Str_KyTuTachChuoi.substring(1)))
            return;
        String[] StrArr_TachTenHam = str_KhaiBao.split(Str_KyTuTachChuoi);

        i_DoDaiCanTo = StrArr_TachTenHam[0].length();
        sD_Doc.setCharacterAttributes(i_STTViTriDau, i_DoDaiCanTo, mA_TenHam, false);

        //Cập nhật lại vị trí đầu và chuổi khai báo
        i_STTViTriDau = str_KhaiBao.indexOf(jEnum_DauPhanCach.TenHam_PhanConLai.value().substring(1));
        str_KhaiBao = str_KhaiBao.split(jEnum_DauPhanCach.TenHam_PhanConLai.value())[1];
        i_STTViTriDau ++;

    //Phần còn lại là các tham số và giá trị trả về
        //Tách các tham số ra
        String[] strArr_CacThamSo = str_KhaiBao.split(jEnum_DauPhanCach.CacThamSoVoiNhau.value());
        
        int i_SoLuongBien = strArr_CacThamSo.length;
        int i = 0;
        for (; i < i_SoLuongBien - 1; i++){
            String str_ThongTinBien = strArr_CacThamSo[i];
            if (!str_ThongTinBien.contains(jEnum_DauPhanCach.TenBien_KieuDuLieu.value().substring(1)))
                return;
            //Cập nhật vị trí cuối tô màu tên tham số và cập nhật lại vị trí đầu
            i_DoDaiCanTo = str_ThongTinBien.split(jEnum_DauPhanCach.TenBien_KieuDuLieu.value())[0].length();
            sD_Doc.setCharacterAttributes(i_STTViTriDau, i_DoDaiCanTo, mA_TenBien, false);
            i_STTViTriDau += i_DoDaiCanTo + 1;

            //Cập nhật vị trí cuối tô màu kiểu dữ liệu và cập nhật lại vị trí đầu
            i_DoDaiCanTo = str_ThongTinBien.split(jEnum_DauPhanCach.TenBien_KieuDuLieu.value())[1].length();
            sD_Doc.setCharacterAttributes(i_STTViTriDau, i_DoDaiCanTo, mA_KieuDuLieu, false);
            i_STTViTriDau += i_DoDaiCanTo  + 1;
        }
        
    //Phần còn lại là tham số cuối và giá trị trả về
        //Tách giá tham số cuối ra
        String str_ThamSoCuoi = strArr_CacThamSo[i].split(jEnum_DauPhanCach.GiaTriTraVe_CacThamSo.value())[0];
        //Tô màu tham số cuối
        if (!str_ThamSoCuoi.contains(jEnum_DauPhanCach.TenBien_KieuDuLieu.value().substring(1)))
                return;
        //Cập nhật vị trí cuối tô màu tên tham số và cập nhật lại vị trí đầu
        i_DoDaiCanTo = str_ThamSoCuoi.split(jEnum_DauPhanCach.TenBien_KieuDuLieu.value())[0].length();
        sD_Doc.setCharacterAttributes(i_STTViTriDau, i_DoDaiCanTo, mA_TenBien, false);
        i_STTViTriDau += i_DoDaiCanTo + 1;

        //Cập nhật vị trí cuối tô màu kiểu dữ liệu và cập nhật lại vị trí đầu
        i_DoDaiCanTo = str_ThamSoCuoi.split(jEnum_DauPhanCach.TenBien_KieuDuLieu.value())[1].length();
        sD_Doc.setCharacterAttributes(i_STTViTriDau, i_DoDaiCanTo, mA_KieuDuLieu, false);
        i_STTViTriDau += i_DoDaiCanTo  + 1;
        
        //Kiểm tra xem có giá trị trả về không nếu không thì kết thúc
        if (!str_KhaiBao.contains(jEnum_DauPhanCach.GiaTriTraVe_CacThamSo.value().substring(1)) || //Chưa có dấu ")"
                str_KhaiBao.endsWith(jEnum_DauPhanCach.GiaTriTraVe_CacThamSo.value().substring(1))) //Kết thúc = dấu ")"
                return;
        //Tô màu tham số cuối
        String str_GiaTriTraVe = strArr_CacThamSo[i].split(jEnum_DauPhanCach.GiaTriTraVe_CacThamSo.value())[1];
        if (!str_ThamSoCuoi.contains(jEnum_DauPhanCach.TenBien_KieuDuLieu.value().substring(1)))
                return;
        //Cập nhật vị trí cuối tô màu tên tham số và cập nhật lại vị trí đầu
        i_DoDaiCanTo = str_GiaTriTraVe.split(jEnum_DauPhanCach.TenBien_KieuDuLieu.value())[0].length();
        sD_Doc.setCharacterAttributes(i_STTViTriDau, i_DoDaiCanTo, mA_TenBien, false);
        i_STTViTriDau += i_DoDaiCanTo + 1;

        //Cập nhật vị trí cuối tô màu kiểu dữ liệu và cập nhật lại vị trí đầu
        i_DoDaiCanTo = str_GiaTriTraVe.split(jEnum_DauPhanCach.TenBien_KieuDuLieu.value())[1].trim().length();
        sD_Doc.setCharacterAttributes(i_STTViTriDau, i_DoDaiCanTo, mA_KieuDuLieu, false);
        i_STTViTriDau += i_DoDaiCanTo  + 1;

     /*
    //Tô màu các tham số
        //Lấy các chuổi chứa các thông tin về các tham số
        String[] StrArr_CacThamSo = StrArr_TachGiaTriTraVe[0].split(jEnum_DauPhanCach.CacThamSoVoiNhau.value());
        for (String str_ThongTinThamSo : StrArr_CacThamSo){
            //Lấy các chuổi chứa các thông tin về các tham số thành các chuổi tên biến và kiểu dữ liệu
            String[] strArr_TachTenBien = str_ThongTinThamSo.split(jEnum_DauPhanCach.TenBien_KieuDuLieu.value());
            if (strArr_TachTenBien.length == 2)    {//Nếu đã đánh xong tên biến
                //Tô màu tên biến
                i_STTViTriCuoi = i_STTViTriDau + strArr_TachTenBien[0].length();
                sD_Doc.setCharacterAttributes(i_STTViTriDau, i_STTViTriCuoi, mA_TenBien, false);
                i_STTViTriDau = i_STTViTriCuoi + 1;
                sD_Doc.setCharacterAttributes(i_STTViTriCuoi, jTextPane_PhanNhapKhaiBao.getText().length(), mA_ChuThuong, false);

                //Tô màu kiểu dữ liêu
                i_STTViTriCuoi = i_STTViTriDau + strArr_TachTenBien[1].length();
                sD_Doc.setCharacterAttributes(i_STTViTriDau, i_STTViTriCuoi, mA_KieuDuLieu, false);
                i_STTViTriDau = i_STTViTriCuoi + 1;
                sD_Doc.setCharacterAttributes(i_STTViTriCuoi, jTextPane_PhanNhapKhaiBao.getText().length(), mA_ChuThuong, false);
            }
        }
    //Tô màu phần tên giá trị trả về
        String[] strArr_TachTenBien = StrArr_TachGiaTriTraVe[1].split(jEnum_DauPhanCach.TenBien_KieuDuLieu.value());
        if (strArr_TachTenBien.length == 2)    {//Nếu đã đánh xong tên biến
            //Tô màu tên biến
            i_STTViTriCuoi = i_STTViTriDau + strArr_TachTenBien[0].length();
            sD_Doc.setCharacterAttributes(i_STTViTriDau, i_STTViTriCuoi, mA_TenBien, false);
            i_STTViTriDau = i_STTViTriCuoi + 1;
            sD_Doc.setCharacterAttributes(i_STTViTriCuoi, jTextPane_PhanNhapKhaiBao.getText().length(), mA_ChuThuong, false);

            //Tô màu kiểu dữ liêu
            i_STTViTriCuoi = i_STTViTriDau + strArr_TachTenBien[1].length();
            sD_Doc.setCharacterAttributes(i_STTViTriDau, i_STTViTriCuoi, mA_KieuDuLieu, false);
            i_STTViTriDau = i_STTViTriCuoi + 1;
            sD_Doc.setCharacterAttributes(i_STTViTriCuoi, jTextPane_PhanNhapKhaiBao.getText().length(), mA_ChuThuong, false);
        }*/
    }
    private void toMau_LoiKieuDuLieu (jClass_Bien jCB_Bien){
        String str_ChuoiKhaiBao = jTextPane_PhanNhapKhaiBao.getText();
        //Tìm vị trí cuối cùng có dạng "jCB_Bien :"
        int i_STTViTriCuaBien = str_ChuoiKhaiBao.lastIndexOf(jCB_Bien.getTen() + ":");

        //Xác định vị trí của kiểu dữ liệu
        int i_STTViTriCanTo = i_STTViTriCuaBien + jCB_Bien.getTen().length() + ":".length(); //

        //Tạo AttributeSet chữ in nghiêng màu đỏ.
        MutableAttributeSet mA_Loi = new SimpleAttributeSet();
        StyleConstants.setForeground(mA_Loi, Color.RED);
        StyleConstants.setItalic(mA_Loi, true);

        StyledDocument doc = jTextPane_PhanNhapKhaiBao.getStyledDocument();
        doc.setCharacterAttributes(i_STTViTriCanTo, jCB_Bien.getKieuDuLieu().length(), mA_Loi, false);
    }
}
